import Vue from 'vue'
import Vuex, { Store } from 'vuex'
import state from './state'
import mutations from './mutation'
import getters from './getters'

Vue.use(Vuex)
// 这是vue里面的插件
const cartPlugin = store => {
  store.subscribe((mutation, state) => {
    // 每当有mutation提交 就会执行这个方法
    // 把state.cart存入localstorage
    localStorage.setItem('cart', JSON.stringify(state.cart))
  })
}

export default new Store({
  plugins: [cartPlugin],
  state,
  mutations,
  getters,
  actions: {
  },
  modules: {
  }
})
